package com.bestcem.xm.wallet.dao.impl;

import com.bestcem.xm.wallet.dao.LimitOrderDao;
import com.bestcem.xm.wallet.dao.mapper.LimitOrderMapper;
import com.bestcem.xm.wallet.entity.mysql.LimitOrder;
import com.bestcem.xm.wallet.entity.pojo.LimitOrderDO;
import com.bestcem.xm.wallet.util.business.DataBaseUtil;
import com.bestcem.xm.wallet.util.convert.LimitOrderConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 限制充值订单dao实现
 *
 * @author wangyunyun <yunyun.wang@idiaoyan.com>
 * @version v1.0
 * @date 2022/5/13 10:34
 */
@Repository
public class LimitOrderDaoImpl implements LimitOrderDao {

    @Resource
    private LimitOrderConvert limitOrderConvert;

    @Resource
    private LimitOrderMapper limitOrderMapper;

    @Override
    public String insert(LimitOrderDO limitOrderDO) {
        // 设置参数
        LimitOrder limitOrder = limitOrderConvert.do2Mysql(limitOrderDO);
        limitOrder.setLimitOrderId(DataBaseUtil.generateId());
        DataBaseUtil.setCreateAndUpdateTime(limitOrder);
        // 新增
        limitOrderMapper.insertSelective(limitOrder);
        // 设置返回值
        return limitOrder.getLimitOrderId();
    }

    @Override
    public Integer updateByCondition(LimitOrderDO param, LimitOrderDO condition) {
        // 设置更新参数
        LimitOrder limitOrder = limitOrderConvert.do2Mysql(param);
        DataBaseUtil.setUpdateTime(limitOrder);
        // 更新
        return limitOrderMapper.updateByCondition(limitOrder, limitOrderConvert.do2Mysql(condition));
    }

    @Override
    public List<LimitOrderDO> selectBySelective(LimitOrderDO limitOrderDO) {
        return limitOrderConvert.mysqls2Dos(
                limitOrderMapper.selectBySelective(limitOrderConvert.do2Mysql(limitOrderDO)));
    }
}
